package com.wnx.job.modules.nms.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.wnx.job.common.api.PageResult;
import com.wnx.job.common.api.QueryPageBean;
import com.wnx.job.modules.nms.dto.ArticleAttachmentParam;
import com.wnx.job.modules.nms.mapper.NmsArticleAttachmentMapper;
import com.wnx.job.modules.nms.model.NmsArticleAttachment;
import com.wnx.job.modules.nms.service.NmsArticleAttachmentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wangnaixing
 * @since 2021-12-16
 */
@Service
public class NmsArticleAttachmentServiceImpl extends ServiceImpl<NmsArticleAttachmentMapper, NmsArticleAttachment> implements NmsArticleAttachmentService {
    @Resource
    private NmsArticleAttachmentMapper articleAttachmentMapper;


    /**
     * 根据文章ID查询文章附件数量
     * @param articleId
     * @return
     */
    @Override
    public long findCountByArticleId(Long articleId) {
        return  articleAttachmentMapper.selectCount(
                new QueryWrapper<NmsArticleAttachment>()
                        .eq("article_id", articleId));
    }

    /**
     * 根据ID查询咨询附件详情
     * @param id
     * @return
     */
    @Override
    public ArticleAttachmentParam findById(Long id) {
        return   articleAttachmentMapper.findById(id);
    }

    /**
     * 分页查询
     * @param queryPageBean
     * @return
     */
    @Override
    public PageResult<ArticleAttachmentParam> findByPage(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        List<ArticleAttachmentParam>  attachments  = articleAttachmentMapper.findAll();
        return PageResult.restPage(attachments);
    }
}
